<template>
	<view class="Page">
		<view class="title">{{breadTar}}</view>
		<view class="kongbai"></view>
		<view class="item" v-for="(item ,i) in list" :key="i" >
			<view @click="textClick(item)">{{item?.name}}</view>
			<view class="icon" v-show="!item?.is_leaf" @click="iconClick(item)">
				<image src="../../static/index/right2.svg" mode="aspectFit" ></image>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
				breadTar:'/',
				// choosedId:0,
				count:0,
				isShangxian:'',
			}
		},
		onLoad(options) {
			this.list=JSON.parse(options.list);
			this.isShangxian=options.isShangxian;
			console.log('this.isShangxian2'+this.isShangxian)
		},
		methods:{
			iconClick(item){
				this.breadTar='/'+item?.display_name;
				let that=this;
				that.$root.http('http://113.15.231.21:180/roll_device/ding_app/query_device_tree_list',
					{
						  org_id: 21,               // 组织ID 写 21
						  is_active: true,           // 默认传
						  page_index: 1,             // 第一页
						  // pageSize: 7,              // 每页8条数据
						  parent_id: item?.id,             // 父级id，第一层级不传
					}, 
					{
						sessionid:that.$root.sessionID
					})
					.then((res) => {
						let fun=function(){
							that.list=[];
							if(res.data.result&&res.data.result.list&&res.data.result.list.length>0){
								console.log(res.data.result.list);
								res.data.result.list.forEach(
									temp => {
										if(temp.parent_id==item?.id){
											that.list.push(temp)
										}
									}
								)
						 
							}
							else{
								that.$root.message('fail','设备树无数据')
							}
						}
						that.$root.judge(res,fun);
					})
			},
			textClick(item){
				console.log('this.isShangxian2'+this.isShangxian)
				if(this.isShangxian=='1'){
					console.log('来')
					dd.redirectTo({
						url:'/pages/shangxian/shangxian?item='+JSON.stringify(item),
					})
				}
				else{
					dd.redirectTo({
						url:'/pages/xiaxian/xiaxian?item='+JSON.stringify(item),
					})
				}

			}
		}
		
	}
</script>

<style scoped>
	.Page{
		width: 100%;
		font-size: 14px;
		background-color: #F6F6F6;
		display: flex;
		flex-direction: column;
		/* align-items: center; */
		padding-left: 10px;
		/* padding-right: 10px; */
		
	}
	.title{
		font-size: 16px;
		margin-top: 10px;
		font-weight: 600;
	}
	.kongbai{
		width: 93%;
		height: 5px;
	}
	.item{
		width: 93%;
		height: 50px;
		background-color: white;
		/* border-bottom: 1px solid black; */
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		font-size: 14px;
		margin-top: 5px;
		border-radius: 5px;
		padding-left: 5px;
	}
	.item:hover{
		box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
	}
	.icon image{
		width: 30px;
		height: 30px;
	}
</style>